package cn.itmantzy.basic.service.impl;

import cn.itmantzy.basic.mapper.BaseMapper;
import cn.itmantzy.basic.query.BaseQuery;
import cn.itmantzy.basic.service.IBaseService;
import cn.itmantzy.basic.util.PageList;
import cn.itmantzy.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T queryById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Long count = baseMapper.queryCount(query); // 查询当前页总条数
        List<T> rows = baseMapper.queryData(query); // 查询当前页信息
        PageList<T> pageList = new PageList<>(count, rows); // 查询出分页数据
        return pageList;
    }

    @Override
    public void removeBatch(Long[] ids) {

    }
}
